﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Filters;
using ESMAM.Model;
using ESMAM.Web.Core.Filters;
using ESMAM.Model.SYS;
using ESMAM.Tools;

namespace ESMAM.Web.Core
{
    [FileFilter]
    [AuthorityFilter]
    public class BaseController : Controller
    {
        /// <summary>
        /// 当前主题
        /// </summary>
        public const string CONST_THEME = "bjui_theme";

        /// <summary>
        /// 当前用户 
        /// </summary>
        public const string CONST_SESSION_USER = "CURRENTUSER";

        
        /// <summary>
        /// 登陆用户名，用于 记住登陆账号 功能使用 
        /// </summary>
        public const string CONST_COOKIE_UNAME = "SYSLOGINNAME";



        /// <summary>
        /// 语言类型
        /// </summary>
        public const string CONST_COOKIE_LANG = "LANGUAGE";

        /// <summary>
        /// 当前登陆用户
        /// </summary>
        public sys_user CurrUser
        {
            get
            {
                return Session[CONST_SESSION_USER] as sys_user;
            }
        }


        /// <summary>
        /// 当前使用语言
        /// </summary>
        public Lang CurrLang
        {
            get
            {
                string strLang = CookieHelper.GetCookieValue(BaseController.CONST_COOKIE_LANG);
                
                return string.IsNullOrWhiteSpace(strLang) ? Lang.en : (Lang)Enum.Parse(typeof(Lang), strLang);
            }
        }

        /// <summary>
        /// 翻译文本
        /// </summary>
        /// <param name="textStr"></param>
        /// <returns></returns>
        public string Trans(string textStr)
        {
            string res = null;

            Lang lg = CurrLang;

            if (lg == Lang.zh)
            {
                res = textStr;
            }
            else if (lg == Lang.en)
            {
                res = ESMAM.BLL.SYS.LangBLL.dict_CN_EN[textStr];
            }
            //else if (lg == Lang.jp)
            //{
            //    res = ESMAM.BLL.SYS.LangBLL.dict_CN_JP[textStr];
            //}
            //else if (lg == Lang.kor)
            //{
            //    res = ESMAM.BLL.SYS.LangBLL.dict_CN_KOR[textStr];
            //}
            else if (lg == Lang.spa)
            {
                res = ESMAM.BLL.SYS.LangBLL.dict_CN_SPA[textStr];
            }
            else
            {
                res = textStr;
            }
            return res ?? textStr;
        }

    }
}

